import { maxNum, minNum } from "./max";

/**
 * 
 * @param {number} newVal 
 * @param {number} oldVal 
 * @param {Comment} component 
 * @param {String} dataKey 
 * @returns 
 */
function parsePage (newVal, oldVal, dataKey = "companys") {

    console.log(this);

    if (newVal === 1) {
      this.lastId = 0;
      console.log("第一页", this.lastId);

      return;
    }

    if (newVal > oldVal && newVal === oldVal + 1) {
      // 页数相邻
      this.lastId = maxNum(this[dataKey], "id");

      console.log("页数相邻", this.lastId);

      return;
    } 
    
    if (newVal > oldVal && newVal !== oldVal + 1) {
      // 跳转的页数 > 大于老页数 且 页码不相邻
      let num = 0;
      num =
      maxNum(this[dataKey], "id") +
        (newVal - oldVal - 1) * (this.pageSize || 30);
        this.lastId = num;

      console.log("跳转的页数 > 大于老页数 且 页码不相邻", this.lastId);

      return;
    }
    
    if (newVal < oldVal) {
      let num1 = 0;
      num1 =
        minNum(this[dataKey], "id") -
        1 -
        (oldVal - newVal) * (this.pageSize || 30);
        this.lastId = num1;

      console.log("跳转的页数 < 大于老页数 且 页码不相邻", this.lastId);
    }
  }

  export {
    parsePage
  }